package com.iflytek.ssm.usermanage.controller;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iflytek.ssm.usermanage.entity.User;
import com.iflytek.ssm.usermanage.service.UserService;
import com.iflytek.ssm.util.ReturnUtil;

@Controller
public class UserController {

	private static final Logger logger = LoggerFactory.getLogger(UserController.class);

	@Autowired
	private UserService userService;

	@GetMapping("/getUserInfo")
	@ResponseBody
	public Object getUserInfo(String name) {
		if (StringUtils.isBlank(name)) {
			return ReturnUtil.fail("name???????");
		}
		logger.info("getUserInfo,name={}", name);
		User user = userService.getByName(name);
		// ModelAndView
		return ReturnUtil.success("??????", user);
	}

	@GetMapping("/user/{id}")
	@ResponseBody
	public Object queryUserInfo(@PathVariable Integer id) {

		User user = userService.queryUserInfo(id);

		return user;

	}

}
